package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.PictureCategory;
import com.stylefeng.guns.modular.system.service.IPictureCategoryService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-07-17 17:04:48
 */
@Controller
@RequestMapping("/pictureCategory")
public class PictureCategoryController extends BaseController {

    private String PREFIX = "/system/pictureCategory/";

    @Autowired
    private IPictureCategoryService pictureCategoryService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "pictureCategory.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/pictureCategory_add")
    public String pictureCategoryAdd() {
        return PREFIX + "pictureCategory_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/pictureCategory_update/{pictureCategoryId}")
    public String pictureCategoryUpdate(@PathVariable Integer pictureCategoryId, Model model) {
        PictureCategory pictureCategory = pictureCategoryService.selectById(pictureCategoryId);
        model.addAttribute("item",pictureCategory);
        LogObjectHolder.me().set(pictureCategory);
        return PREFIX + "pictureCategory_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return pictureCategoryService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(PictureCategory pictureCategory) {
        pictureCategoryService.insert(pictureCategory);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer pictureCategoryId) {
        pictureCategoryService.deleteById(pictureCategoryId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(PictureCategory pictureCategory) {
        pictureCategoryService.updateById(pictureCategory);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{pictureCategoryId}")
    @ResponseBody
    public Object detail(@PathVariable("pictureCategoryId") Integer pictureCategoryId) {
        return pictureCategoryService.selectById(pictureCategoryId);
    }
}
